package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Spot;
import cn.wolfcode.wolf2w.query.SpotQuery;
import cn.wolfcode.wolf2w.service.ISpotService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
* 景点控制层
*/
@Controller
@RequestMapping("spot")
public class SpotController {

    @Autowired
    private ISpotService spotService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") SpotQuery qo){
        Page<Spot> page = spotService.query(qo);
        model.addAttribute("page", page);

        return "spot/list";
    }

    @RequestMapping("/get")
    @ResponseBody
    public Object get(String id){
        return JsonResult.success(spotService.get(id));
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Spot spot){
        //状态 序号 录入时间
        //
        //id 名称  图片  简介  电话  网址   用时参考  交通   门票价格   开放时间
        spot.setImgUrl("/images/test/spot/wKgB3FIMRvaAdrjoAAGCmIetJvQ75.jpeg");
        spot.setInfo("...");
        spot.setName("桂林");
        spot.setTel("0359-6182223");
        spot.setUrl("www.桂林.com");
        spot.setUseTime(1);
        spot.setTraffic("飞机直达");
        spot.setTicket("50000一张");
        spot.setOpenTime("3点-10点");
        spot.setSequence(2);


        spotService.saveOrUpdate(spot);

        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        spotService.delete(id);
        return JsonResult.success();
    }
}
